#include "string.h"

void* memset(void *dst, int c, size_t n) {
    char *cdst = (char *)dst;
    for (size_t i = 0; i < n; i++) {
        cdst[i] = c;
    }
    return dst;
}

void* memcpy(void *dst, const void *src, size_t n) {
    char *cdst = (char *)dst;
    const char *csrc = (const char *)src;
    for (size_t i = 0; i < n; i++) {
        cdst[i] = csrc[i];
    }
    return dst;
}

int memcmp(const void *s1, const void *s2, size_t n) {
    const char *cs1 = (const char *)s1;
    const char *cs2 = (const char *)s2;
    for (size_t i = 0; i < n; i++) {
        if (cs1[i] != cs2[i]) {
            return cs1[i] - cs2[i];
        }
    }
    return 0;
}

size_t strlen(const char *s) {
    size_t len = 0;
    while (s[len] != '\0') {
        len++;
    }
    return len;
}

char* strcpy(char *dst, const char *src) {
    char *ret = dst;
    while ((*dst++ = *src++) != '\0');
    return ret;
}

int strcmp(const char *s1, const char *s2) {
    while (*s1 && *s1 == *s2) {
        s1++;
        s2++;
    }
    return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}
